using CoreProject.IRepository;
using CoreProject.Model;
using Microsoft.EntityFrameworkCore;

namespace CoreProject.Repository
{
  public class RolesRepository : BaseRepository<Role>, IRolesRepoistory
  {
    private readonly EFDbContext _dbContext;

    public RolesRepository(EFDbContext dbContext):base(dbContext) 
    {
      _dbContext = dbContext;
    }

        public async Task<(List<Role> list, int count)> GetRoleBypage(string name, int page, int size)
        {
            var data = await _dbContext.Roles.Include(m => m.Dept).ToListAsync();

            if (!string.IsNullOrWhiteSpace(name))
            {
                data = data.Where(n => n.RoleName.Contains(name)).ToList();
            }
            int count = data.Count();
            var pagelist = data.OrderBy(n => n.RoleId).Skip((page - 1) * size).Take(size);
            return (pagelist.ToList(), count);
        }
    }
}
